
const defaultState = {
    // 消息提示类型
    type: '',

    // 消息提示内容
    text: '',

    // 是否显示
    isOpen: false,

    // 时间
    duration: 0
};

/**
 * 显示消息提示栏
 * @type {String}
 */
export const SHOW_NOTIFICATION = 'SHOW_NOTIFICATION';

/**
 * 关闭消息提示栏
 * @type {String}
 */
export const HIDE_NOTIFICATION = 'HIDE_NOTIFICATION';

/**
 * 消息提示栏 Reducer
 * @param {Object} state
 * @param {Object} action
 */
export default function notificationsReducer(state = defaultState, action) {
    switch (action.type) {
        case SHOW_NOTIFICATION:
            return {
                ...state,
                type: action.payload.type,
                text: action.payload.text,
                duration: action.payload.duration,
                isOpen: true
            };
        case HIDE_NOTIFICATION:
            return {
                ...state,
                isOpen: false
            };
        default:
            return state;
    }
}